import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:wanke/about_page.dart';
import 'package:wanke/account_page.dart';
import 'package:wanke/feedback_page.dart';
import 'package:wanke/safe_page.dart';
import 'function.dart';

class UserInfo extends StatefulWidget {
  UserInfo(this.mainColor);
  final mainColor;
  @override
  _UserInfoState createState() => new _UserInfoState();
}

class _UserInfoState extends State<UserInfo> {
  String uid = "";
  bool logout = false;
  @override
  void initState() {
    initUser();
    super.initState();
  }

  Future<bool> willPop() {
    print(this.logout);
    Navigator.of(context).pop(this.logout);
    return new Future.value(false);
  }

  initUser() async {
    this.uid = await getStorage("uid");
  }

  @override
  Widget build(BuildContext context) {
    return new WillPopScope(
        child: Scaffold(
          appBar: new CupertinoNavigationBar(
            actionsForegroundColor: Colors.white,
            backgroundColor: widget.mainColor,
            middle: new Text(
              "用户设置",
              style: new TextStyle(
                color: Colors.white,
                fontWeight: FontWeight.normal,
              ),
            ),

          ),
          body: new Container(
            child: new Column(
              children: <Widget>[
                new Expanded(
                    child: new ListView(
                      children: <Widget>[
                        new ListTile(
                          onTap: () {
                            Navigator.of(context).push(
                              new CupertinoPageRoute(builder: (context) {
                                return new SafePage(widget.mainColor);
                                //return new PasswordPage(mainColor);
                              }),
                            );
                          },
                          leading: new ImageIcon(AssetImage("images/safe.png")),
                          title: new Text("安全设置"),
                          trailing: new Icon(Icons.chevron_right),
                        ),
                        new Divider(
                          height: 1.0,
                        ),
                        new ListTile(
                          onTap: () {
                            Navigator.of(context).push(
                              new CupertinoPageRoute(builder: (context) {
                                return new AccountPage(widget.mainColor);
                              }),
                            );
                          },
                          leading: new Icon(Icons.phone_iphone),
                          title: new Text("账号绑定"),
                          trailing: new Icon(Icons.chevron_right),
                        ),
                        new Divider(
                          height: 1.0,
                        ),
                        new ListTile(
                          onTap: () {
                            Navigator.of(context).push(
                              new CupertinoPageRoute(builder: (context) {
                                return new FeedbackPage(widget.mainColor);
                              }),
                            );
                          },
                          leading: new ImageIcon(AssetImage("images/feedback.png")),
                          title: new Text("反馈建议"),
                          trailing: new Icon(Icons.chevron_right),
                        ),
                        new Divider(
                          height: 1.0,
                        ),
                        new ListTile(
                          onTap: () {
                            Navigator.of(context).push(
                              new CupertinoPageRoute(builder: (context) {
                                return new AboutPage(widget.mainColor);
                                //return new PasswordPage(mainColor);
                              }),
                            );
                          },
                          leading: new Icon(Icons.info),
                          title: new Text("关于随行"),
                          trailing: new Icon(Icons.chevron_right),
                        ),
                        new Divider(
                          height: 1.0,
                        ),
                        new ListTile(
                          leading: new Icon(Icons.exit_to_app),
                          title: new Text("注销登录"),
                          trailing: new Icon(Icons.chevron_right),
                          onTap: () {
                            showDialog(
                              context: context,
                              builder: (BuildContext context) {
                                return AlertDialog(
                                  title: const Text('注销登录'),
                                  actions: <Widget>[
                                    FlatButton(
                                      child: Text(
                                        '注销',
                                        style: new TextStyle(fontWeight: FontWeight.bold, color: Colors.red),
                                      ),
                                      onPressed: () {
                                        removeStorage("uid");
                                        toast("注销成功");
                                        this.logout = true;
                                        setState(() {});
                                        Navigator.of(context).pop();
                                      },
                                    ),
                                    FlatButton(
                                      child: Text('取消'),
                                      onPressed: () {
                                        Navigator.of(context).pop();
                                      },
                                    ),
                                  ],
                                );
                              },
                            );
                          },
                        ),
                        new Divider(
                          height: 1.0,
                        ),
                      ],
                    ))
              ],
            ),
          ),
        ),
        onWillPop: willPop);
  }
}
